{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Url::build('/admin/post/addpost')}">
        <input type="hidden" name="id" value="{$post.id}">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">所属栏目：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <div class="select-box">
                    <select name="category_id" class="select">
                        <option value="">请选择</option>
                        {volist name="menus" id="v"}
                        {if condition="$Request.action eq 'addpost'"}
                        <option value="{$v.id}">{$v.name}</option>
                        {else /}
                        <option value="{$v.id}" {if condition="$post.category_id eq $v.id"}selected{/if}>{$v.name}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>新闻标题：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$post.title}" placeholder="新闻标题" name="title">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">海报：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" id="upload" placeholder="请点击后面的上传按钮" name="poster" value="{$post.poster}" style="width: 70%">
                <button type="button" class="btn btn-primary radius" onclick="layer_open('文件上传','{:\\think\\Url::build(\'Upload/index\', [\'id\' => \'upload\'])}')">上传</button>
                <a onclick="$(this).attr('href', $('#upload').val())" type="button" class="btn btn-success radius" data-lightbox="preview">预览</a>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">关键词：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$post.keyword}" placeholder="关键词" name="keyword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">摘要：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <textarea class="textarea" placeholder="不填写，则截取文章一小段内容" name="description" onKeyUp="textarealength(this,100)">{$post.description}</textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">文章内容：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <script id="editor" type="text/plain" name="content" style="height:800px">{$post.content}</script>
                </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <button type="button" class="btn btn-primary radius" id="tijiao">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                        <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                    </div>
                </div>
    </form>
</div>
{/block}
{block name="style"}
    <link rel="stylesheet" href="__LIB__/lightbox2/css/lightbox.min.css">
{/block}
{block name="script"}
<script src="__LIB__/lightbox2/js/lightbox.min.js"></script>
<script>window.UEDITOR_HOME_URL = '__LIB__/ueditor/1.4.3/'</script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script>
    $(function () {
        var ue = UE.getEditor('editor',{
            serverUrl:'{:\\think\\Url::build("Ueditor/index")}',
            imageFieldName: 'img'
        });
        $('#tijiao').on('click', function () {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var id = $("input[name='id']").val();
            var title = $("input[name='title']").val(),
                poster = $("input[name='poster']").val(),
                keyword = $("input[name='keyword']").val(),
                category_id = $("select[name='category_id']").val(),
                description = $("textarea[name='description']").val();
            var html = ue.getContent();
            html = encodeURIComponent(html);
            var data = {
                title: title,
                poster: poster,
                keyword: keyword,
                category_id: category_id,
                description: description,
                content: html
            };
            $.ajax({
                url: '/admin/post/edit/id/' + id,
                type: 'post',
                dataType: 'json',
                data: {data: data},
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('保存成功', function () {
                            layer_close();
                        });
                    }
                }
            });
        });
    })
</script>
{/block}